#!/bin/bash

inputFilePath="$1"
destDirectory="$2"
fileName="$3"

fileNameR=$(basename "$fileName" | cut -d. -f1)
m3u8FilePath="$destDirectory/${fileNameR}.m3u8"
tsFilePattern="$destDirectory/${fileNameR}_%03d.ts"

# Set duration to 60 seconds (1 minute)
duration="60"

ffmpeg -i "$inputFilePath" \
    -c:v libx264 \
    -c:a aac \
    -b:a 128k \
    -b:v 400k \
    -vf fps=25 \
    -f hls \
    -hls_time 10 \
    -hls_list_size 0 \
    -hls_segment_filename "$tsFilePattern" \
    -t "$duration" \
    "$m3u8FilePath"
